<template>
  <div>
    <el-cascader
      v-model="pid"
      :options="list"
      :props="{ checkStrictly: true,label:'title',value:'id',emitPath:false }"
      clearable
    />

  </div>
</template>
<script>
import {
  findAllPermissions as findAllPermissionsApi
} from '@/api/auth/roles.js'
// Load the full build.
var _ = require('lodash')
export default {
  name: 'Source',
  mixins: [],
  data() {
    return {
      pid: '',
      menuList: []
    }
  },
  computed: {
    list() {
      const newList = _.cloneDeep(this.menuList)
      // console.log('newList==>', newList)
      this.buildList(newList)
      return newList
    }
  },
  watch: {
  },
  created() {
    this.getPermissionList()
  },
  mounted() {
  },
  methods: {
    async getPermissionList() {
      const res = await findAllPermissionsApi()
      this.menuList = res.data.menus
    },
    buildList(arr) {
      for (let i = 0; i < arr.length; i++) {
        const item = arr[i]
        if (item.type === 2) { // 按钮
          item.disabled = true
        }
        if (item.children && item.children.length > 0) {
          this.buildList(item.children)
        } else {
          // 删除空数组
          delete item.children
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
